
// Core frame size (header 12) + (CRC32, 4byte) = 16 bytes 
#define CORE_FRAME_SIZE 16

// Maximum size of data field of command frame 
#define MAX_COMMAND_DATA_SIZE  4096

// Maximum size of data field of reply frame 
#define MAX_REPLY_DATA_SIZE    1280000

// Maximum size of command frame = core frame size + max command data size 
#define MAX_COMMAND_FRAME_SIZE  (CORE_FRAME_SIZE + MAX_COMMAND_DATA_SIZE)

// Maximum size of reply frame = core frame size + max reply data size 
#define MAX_REPLY_FRAME_SIZE    (CORE_FRAME_SIZE + MAX_REPLY_DATA_SIZE)

#define SERVER_PORT 37709  //socket listening port

typedef struct _Labview_socket_Data
{
	HANDLE handle_mutex;
	HANDLE handle_thread;
	WSADATA wsa_data;
	SOCKET listen_socket;
	char receive_buff[MAX_COMMAND_FRAME_SIZE];
	int receive_len;
	char reply_buff[MAX_REPLY_FRAME_SIZE];
	int reply_len;
} Labview_socket_Data;

typedef struct _Labview_socket_Data *p_Labview_socket_Data; 

static DWORD WINAPI labview_socket_thread(LPVOID param);

int Labview_socket_Init(void);
int Labview_socket_De_init(void);
int Labview_socket_Start(void);
int Labview_socket_Stop(void);

static int Labview_Socket_ClientHandler(SOCKET client_socket);